package com.dididoctor.doctor.Activity.Usercentre.MyService;

import android.content.Context;

import com.dididoctor.doctor.Activity.ConstantValue;
import com.dididoctor.doctor.Activity.Main.Consult;
import com.dididoctor.doctor.Bean.Token;
import com.dididoctor.doctor.Http.MyHttpResponseHandler;
import com.dididoctor.doctor.MV.BasePresenter;
import com.dididoctor.doctor.MV.BusinessClient;
import com.dididoctor.doctor.MV.Response;
import com.dididoctor.doctor.Utils.Util;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;

/**
 * Created by Administrator on 2016/4/8.
 */
public class MyServicePresenter extends BasePresenter {

    private MyServiceView view;

    public MyServicePresenter(Context context, MyServiceView view) {
        super(context, view);
        this.view = view;
    }

    public void updatestatus(final String type, final boolean isswitch) {
        String status = "";
        RequestParams params = new RequestParams();
        params.put("userId", Token.getUserId());
        params.put("token", Token.getToken());
        params.put("type", type);
        if (isswitch) {
            status = "1";
        } else {
            status = "0";
        }
        params.put("status", status);
        BusinessClient.post(ConstantValue.doctorswitch, params, new MyHttpResponseHandler() {

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    view.updatestatesucced(type, isswitch);
                } else {
                    view.showToastMessage(response.getMsg());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.updatestatefail();
            }
        });
    }

    public void getdoctorInfo() {
        RequestParams params = new RequestParams();
        params.put("userId", Token.getUserId());
        params.put("token", Token.getToken());
        BusinessClient.post(ConstantValue.mainPage, params, new MyHttpResponseHandler() {
                    private String hasDoctor = "";//是否有签约医生1有0没有

                    @Override
                    public void onMyResponse(Response response) {
                        if (response.isSucceed()) {
                            Consult doctor = new Consult();
                            doctor.setUserId(Util.toString(response.getString("userId")));
                            doctor.setOnline(Util.toString(response.getString("online")));
                            doctor.setIsSign(Util.toString(response.getString("isSign")));
                            doctor.setCallSwitch(Util.toString(response.getString("callSwitch")));
                            doctor.setHeadPic(Util.toString(response.getString("headPic")));
                            doctor.setName(Util.toString(response.getString("name")));
                            doctor.setPhone(Util.toString(response.getString("phone")));
                            doctor.setQrcode(Util.toString(response.getString("qrcode")));
                            doctor.setEvaluate(Util.toString(response.getString("evaluate")));
                            doctor.setSignNum(Util.toString(response.getString("signNum")));
                            doctor.setPosition(Util.toString(response.getString("position")));
                            doctor.setAccId(Util.toString(response.getString("accId")));
                            doctor.setAccPwd(Util.toString(response.getString("accPwd")));
                            doctor.setToken(Util.toString(response.getString("token")));

                            view.getdoctorsucced(doctor);
                        } else {
                            view.showToastMessage(response.getMsg());
                        }

                    }

                    @Override
                    public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                        super.onFailure(i, headers, bytes, throwable);
                        view.getdoctorfail();
                    }
                }

        );
    }
}
